var that
const app = getApp()
var index
Page({
  /**
   * 页面的初始数据
   */
  data: {
    top:0, 
    _id:[],
    avatarUrl:'',
    color0:1,
    color1:'#000000',
    color2:'#b6b6b6',
    videoimage: "block" ,//默认显示封面-视频播放的js
    bindplay: null,
    _index:0,
      indicatorDots: true,
      autoplay: true,
      interval: 5000,
      duration: 1000,

      trendsList:[
        {
          id: "1", 
          auto:true,
          seeMore:true,
          imgUrl: 'cloud://test-5gwxfg0see31cde1.7465-test-5gwxfg0see31cde1-1308718724/0.jpg',
          text:''
        },
        {
          id: "2", 
          auto:true,
          seeMore:true,
          imgUrl: 'cloud://test-5gwxfg0see31cde1.7465-test-5gwxfg0see31cde1-1308718724/1.jpg',
          text:""
        },  
        {
          id: "3", 
          auto:true,
          seeMore:true,
          imgUrl: 'cloud://test-5gwxfg0see31cde1.7465-test-5gwxfg0see31cde1-1308718724/2.jpg',
          text:""
        }  ,
        {
          id: "4", 
          auto:true,
          seeMore:true,
          imgUrl: 'cloud://test-5gwxfg0see31cde1.7465-test-5gwxfg0see31cde1-1308718724/3.jpg',
          text:""
        },
        {
          id: "5", 
          auto:true,
          seeMore:true,
          imgUrl: 'cloud://test-5gwxfg0see31cde1.7465-test-5gwxfg0see31cde1-1308718724/4.jpg',
          text:""
        }
      ]
  },
/**
   * 生命周期函数--监听页面加载
   */
  onLoad: function (options) {
    var that = this;
   
    var i=0
    var j=1
    var k=2
    var z=3
    var m=4
    var _k1 = 'trendsList['+i+'].text'  
    var _k2 = 'trendsList['+j+'].text'  
    var _k3 = 'trendsList['+k+'].text'  
    var _k4 = 'trendsList['+z+'].text'  
    var _k5 = 'trendsList['+m+'].text'  
    wx.cloud.downloadFile({
      fileID: 'cloud://test-5gwxfg0see31cde1.7465-test-5gwxfg0see31cde1-1308718724/'+i+'.txt'
    }).then(res => {
      console.log(res.tempFilePath)
      let fs=wx.getFileSystemManager()
      let result = fs.readFileSync(res.tempFilePath,"utf-8")
      this.setData({
        [_k1]: result
      })
    })

    wx.cloud.downloadFile({
      fileID: 'cloud://test-5gwxfg0see31cde1.7465-test-5gwxfg0see31cde1-1308718724/'+j+'.txt'
    }).then(res => {
      console.log(res.tempFilePath)
      let fs=wx.getFileSystemManager()
      let result = fs.readFileSync(res.tempFilePath,"utf-8")
      this.setData({
        [_k2]: result
      })
    })

    wx.cloud.downloadFile({
      fileID: 'cloud://test-5gwxfg0see31cde1.7465-test-5gwxfg0see31cde1-1308718724/'+k+'.txt'
    }).then(res => {
      console.log(res.tempFilePath)
      let fs=wx.getFileSystemManager()
      let result = fs.readFileSync(res.tempFilePath,"utf-8")
      this.setData({
        [_k3]: result
      })
    })

    wx.cloud.downloadFile({
      fileID: 'cloud://test-5gwxfg0see31cde1.7465-test-5gwxfg0see31cde1-1308718724/'+z+'.txt'
    }).then(res => {
      console.log(res.tempFilePath)
      let fs=wx.getFileSystemManager()
      let result = fs.readFileSync(res.tempFilePath,"utf-8")
      this.setData({
        [_k4]: result
      })
    })
    
    wx.cloud.downloadFile({
      fileID: 'cloud://test-5gwxfg0see31cde1.7465-test-5gwxfg0see31cde1-1308718724/'+m+'.txt'
    }).then(res => {
      console.log(res.tempFilePath)
      let fs=wx.getFileSystemManager()
      let result = fs.readFileSync(res.tempFilePath,"utf-8")
      this.setData({
        [_k5]: result
      })
    })
  },
  scrollTopFun(e){
    let that = this;
    that.top = e.detail.scrollTop;
    that.$apply();
  },

  onShow: function() {
    console.log("监听页面显示");
  },
  /**
   * 获取页面列表数据-不用
   * 
   */
  getData: function() {
  

  },
  /**
   *饮食
   */
  wen:function(e){
    var that = this;
  //添加以上  此页固定显示主界面
    wx.navigateTo({
      url: '../push/push',
    })
  },
  /**
   *运动
   */
  sport:function(e){
    wx.navigateTo({
      url: '../push/sport',
    })
    
  },
  
 

  /**
   * 页面相关事件处理函数--监听用户下拉动作
   */
  onPullDownRefresh: function() {
    wx.showNavigationBarLoading() //在标题栏中显示加载
    that.getData();
  },

  /**
   * 页面上拉触底事件的处理函数
   */
    /**
   * 页面上拉触底事件的处理函数
   */
  onReachBottom: function () {
    // 提示无数据
    if (this.data.trendsList.length < this.data.totalCount) {
     
    }
    else{
      wx.showToast({
        title: '期待下周更新',
      })
    }

  },

  /**
   * 用户点击右上角分享
   */
  onShareAppMessage: function() {

  },

  onTapToDetail:function(event){
    //获取当前文章的id
    var postId=event.currentTarget.dataset.postId;
    console.log(postId);
    wx.navigateTo({
      url: 'post-detail/post-detail?id='+postId,
    })
  },

  onCommentTap:function(event){
    var id=event.currentTarget.dadaset.postId;
    wx.navigateTo({
      url: 'post-comment?id='+id,
    })
  },

  OnSwiperTap:function(event){
    var postId=event.target.dataset.postId;
    wx.navigateTo({
      url: 'post-detail/post-detail?id='+postId,
    })
  },

 //展开更多
 toggleHandler: function (e) {
  var that = this;
  index = e.currentTarget.dataset.index;
  for (var i = 0; i < that.data.trendsList.length; i++) {
   if (index == i) {
    that.data.trendsList[index].auto = true;
    that.data.trendsList[index].seeMore = false;
   }
  }
  that.setData({
   trendsList: that.data.trendsList
  })
 },
 //收起更多
 toggleContent: function (e) {
  var that = this;
  index = e.currentTarget.dataset.index;
  for (var i = 0; i < that.data.trendsList.length; i++) {
   if (index == i) {
    that.data.trendsList[index].auto = true;
    that.data.trendsList[index].seeMore = true;
   }
  }
  that.setData({
   trendsList: that.data.trendsList
  })
 },

})